package cn.com.duiba.millionaire.center.biz.service;

import cn.com.duiba.millionaire.center.api.dto.ConReLiveCardSearchDto;
import cn.com.duiba.millionaire.center.api.msg.LoadReliveCardMsg;
import cn.com.duiba.millionaire.center.api.remoteservice.RemoteShareCodeService;
import cn.com.duiba.millionaire.center.biz.TransactionalTestCaseBase;
import cn.com.duiba.millionaire.center.biz.bo.ConsumeAccountParam;
import cn.com.duiba.millionaire.center.biz.bo.ConsumeRenascenceParam;
import cn.com.duiba.millionaire.center.biz.constants.DsConstants;
import com.google.common.collect.Sets;
import org.assertj.core.util.Lists;
import org.javatuples.Pair;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * Created by sty on 1/23/18.
 */
@Transactional(DsConstants.MILLIONAIRE_CONFIG)
public class ConsumerService extends TransactionalTestCaseBase {

    @Autowired
    private MillionaireConsumerService millionaireConsumerService;
    @Autowired
    private RenascenceRecordService renascenceRecordService;
    @Autowired
    private UserAccountService userAccountService;
    @Autowired
    private RemoteShareCodeService remoteShareCodeService;

    @Test
    @Rollback(false)
    public void getNewUser(){

        millionaireConsumerService.findByConsumerId(7426L,1L,"bibibi");
    }


    @Test
    @Rollback(false)
    public void shareCode(){

        remoteShareCodeService.inviteUser("0000g0",1L,1L);
    }

    @Test
    @Rollback(false)
    public void userRe(){
        List<ConsumeRenascenceParam> consumeRenascenceParams= Lists.newArrayList();
        ConsumeRenascenceParam a1=new ConsumeRenascenceParam();
        a1.setActivityId(1L);
        a1.setNum(1);
        a1.setQuestionIndex(1);
        a1.setCid(Sets.newHashSet(14L,314378L,1L));
        consumeRenascenceParams.add(a1);
        millionaireConsumerService.findByConsumerId(1L,1L,null);
        renascenceRecordService.consumeRenascenceCard(consumeRenascenceParams);
        millionaireConsumerService.findByConsumerId(1L,1L,null);
    }

    @Test
    @Rollback(false)
    public void userFindReLiveCard(){
        List<ConReLiveCardSearchDto> users = Lists.newArrayList();
        ConReLiveCardSearchDto one = new ConReLiveCardSearchDto();
        one.setActivityId(1L);
        one.setConsumerId(1L);
        users.add(one);
        ConReLiveCardSearchDto one2 = new ConReLiveCardSearchDto();
        one2.setActivityId(1L);
        one2.setConsumerId(14L);
        users.add(one2);
        ConReLiveCardSearchDto one3 = new ConReLiveCardSearchDto();
        one3.setActivityId(1L);
        one3.setConsumerId(738307L);
        users.add(one3);
        renascenceRecordService.findConsumerReLiveCardByCids(users);
    }

    @Test
    @Rollback(false)
    public void userIntoRedis(){
        LoadReliveCardMsg msg = new LoadReliveCardMsg();
        msg.setActivityId(1L);
        msg.setConsumerId(1L);
        LoadReliveCardMsg msg2 = new LoadReliveCardMsg();
        msg2.setActivityId(1L);
        msg2.setConsumerId(314378L);
        renascenceRecordService.batchLoadFromDatabase(Lists.newArrayList(msg,msg2));
    }

    @Test
    @Rollback(false)
    public void userAccount(){
        ConsumeAccountParam a1=new ConsumeAccountParam();
        a1.setActivityId(1L);
        a1.setAmount(2);
        Set<Pair<Long, Long>> pair=Sets.newHashSet();

        pair.add(new Pair<>(1L,1L));
        pair.add(new Pair<>(314378L,1L));
        a1.setCidAppIdSet(pair);
        userAccountService.addConsumerAccount(a1);
    }
}
